// pages/Fl_Pinglun/index.js
Page({

  /**
   * 页面的初始数据
   */
	data: {
		StarImageIndex: ['0.5', '1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0'],
		StarImageIndex1: ['0.5', '1.0', '1.5', '2.0', '2.5', '3.0', '3.5', '4.0', '4.5', '5.0'],
		StarImagePath: ['../../images/w/26.png', '../../images/w/27.png', '../../images/w/28.png', '../../images/w/29.png', '../../images/w/30.png', '../../images/w/31.png', '../../images/w/32.png', '../../images/w/33.png', '../../images/w/34.png', '../../images/w/35.png'],
		pic: "../../images/w/35.png",
		score: "5.0",
		pic1: "../../images/w/35.png",
		score1: "5.0",
		TabIndexDataList: [],
		tempArrAll: [],
		O_ID: "",
	},


  /**
   * 生命周期函数--监听页面加载
   */
	onLoad: function (options) {
		var _this = this;
		console.log(_this.data.score);
		console.log("cccccccccc");
		console.log(options);
		_this.setData({
			O_ID: options.O_ID,
		})
		wx.request({
			url: "https://www.chnode.xyz/api/Order_State.ashx?",
			data: {
				DataType: "OrderDetail",
				Token: getApp().data.Token,
				O_ID: options.O_ID,
				// page: 1,
			},
			success: function (res) {
				console.log("vvvvvv");
				console.log(res.data.datas.OrderSub)
				if (res.data.type == "datas") {
					_this.setData({
						TabIndexDataList: res.data.datas.OrderSub,
						datas: res.data.datas,
					})
					console.log(_this.data.TabIndexDataList.length);
					var n = _this.data.TabIndexDataList.length;
					for (var i = 0; i < n; i++) {

						_this.data.TabIndexDataList[i].StarImageIndex = _this.data.StarImageIndex;
						_this.data.TabIndexDataList[i].score = "5.0";
						_this.data.TabIndexDataList[i].StarImagePath = _this.data.StarImagePath;
						_this.data.TabIndexDataList[i].pic = "../../images/w/35.png"
						_this.data.TabIndexDataList[i].ImgItems = _this.data.tempArrAll
						_this.data.TabIndexDataList[i].Note = ""


						_this.setData({
							TabIndexDataList: _this.data.TabIndexDataList
						})
					}


				} else {
					_this.setData({
						TabIndexDataList: "",
					})
				}
			},
			complete: function () { wx.hideNavigationBarLoading() }
		})

	},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
	onReady: function () {

	},

  /**
   * 生命周期函数--监听页面显示
   */
	onShow: function () {

	},

  /**
   * 生命周期函数--监听页面隐藏
   */
	onHide: function () {

	},

  /**
   * 生命周期函数--监听页面卸载
   */
	onUnload: function () {

	},

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
	onPullDownRefresh: function () {

	},

  /**
   * 页面上拉触底事件的处理函数
   */
	onReachBottom: function () {

	},

  /**
   * 用户点击右上角分享
   */
	onShareAppMessage: function () {

	},

	//商品点击
	goodsClicked: function (e) {
		var _this = this;
		var n = _this.data.TabIndexDataList.length;

		_this.data.TabIndexDataList[e.currentTarget.dataset.indexa].pic = _this.data.TabIndexDataList[e.currentTarget.dataset.indexa].StarImagePath[e.currentTarget.dataset.indexb];

		_this.data.TabIndexDataList[e.currentTarget.dataset.indexa].score = _this.data.TabIndexDataList[e.currentTarget.dataset.indexa].StarImageIndex[e.currentTarget.dataset.indexb];


		_this.setData({
			TabIndexDataList: _this.data.TabIndexDataList
		})

	},

	//安装点击
	anzhuangClicked: function (e) {
		var _this = this;


		_this.setData({
			score1: _this.data.StarImageIndex[e.currentTarget.dataset.indexc],
			pic1: _this.data.StarImagePath[e.currentTarget.dataset.indexc],
		})

	},

	picClicked: function (e) {
		var _this = this;


		wx.chooseImage({
			success: function (res) {
				var tempFilePaths = res.tempFilePaths
				wx.uploadFile({
					url: 'https://www.chnode.xyz/api/Comment.ashx?DataType=CommentImgUpload&Token=' + getApp().data.Token + '&file=', //仅为示例，非真实的接口地址
					filePath: tempFilePaths[0],
					name: 'file',
					success: function (res) {
						var temp = { ImgUrl: JSON.parse(res.data).data.imgurl, Order: "" };
						_this.data.TabIndexDataList[e.currentTarget.dataset.indexd].ImgItems.push(temp)
						_this.setData({
							TabIndexDataList: _this.data.TabIndexDataList,
						})
					}
				})
			}
		})
	},



	bindTextAreaBlur: function (e) {
    
		var _this = this;
    console.log(e.detail.value);
    
		_this.data.TabIndexDataList[e.currentTarget.dataset.indexa].Note = e.detail.value;
		_this.setData({
			TabIndexDataList: _this.data.TabIndexDataList,
		})

    
	},



	fabuClicked: function (e) {
		var _this = this;
		var arrInput = [];
		var tempKeyAll = [];
		for (var i = 0; i < _this.data.TabIndexDataList.length; i++) {

      console.log(_this.data.TabIndexDataList[i].Note);

      var a123 = "";
      if (_this.data.TabIndexDataList[i].Note.length == 0) {

        a123 = "好评";
      } else {
        a123 = _this.data.TabIndexDataList[i].Note;
      }


			var tempKey = {
				UserScore: _this.data.TabIndexDataList[i].score,
				ImgItems: _this.data.TabIndexDataList[i].ImgItems,
				Note: a123,
				OS_ID: _this.data.TabIndexDataList[i].OS_ID,
				P_ID: _this.data.TabIndexDataList[i].P_ID,
			};
			tempKeyAll.push(tempKey);
		}
		var CommentJson = { ServerScore: _this.data.score1, CommentDatas: tempKeyAll };

    console.log(getApp().data.Token);
    console.log(_this.data.O_ID);
    console.log(JSON.stringify(CommentJson));

		wx.request({
			url: "https://www.chnode.xyz/api/Comment.ashx?",
			data: {
				DataType: "CommentAdd",
				Token: getApp().data.Token,
				O_ID: _this.data.O_ID,
				CommentJson: JSON.stringify(CommentJson)
			},
			success: function (res) {
				console.log(res)
				if (res.data.isok == "false") {
          wx.showModal({
            title: '提示',
            content: res.data.info,
            showCancel:false,
            success: function (res) {
              if (res.confirm) {
                console.log('用户点击确定')
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })  
				} else {

          wx.showModal({
            title: '提示',
            content: res.data.info,
            showCancel:false,
            success: function (res) {
              if (res.confirm) {
                console.log('用户点击确定')

                wx.switchTab({
                  url: '../Fl_Index/index',
                })

                
              } else if (res.cancel) {
                console.log('用户点击取消')
              }
            }
          })  
					
				}
			}
		})
	}
})